package com.suwish.pc.ui.dialog;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

import com.suwish.pc.adb.AdbManager;
import com.suwish.pc.adb.Command;
import com.suwish.pc.ui.component.UIDialog;
import com.suwish.pc.util.StringUtils;
/**
 * 
 * @author Min
 * @deprecated
 *
 */
public class AdbDeviceSelectDialog extends UIDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Window parent = null;
	
	private DefaultListModel listModel = null;
	private JList deviceList = null;
	private JButton submitButton = null;
	private JButton cancelButton = null;
	public AdbDeviceSelectDialog(Window parent){
		super(parent, "Devices");
		setModal(true);
		
		initUI();
		initData();
		initEvent();
		
		setSize(new Dimension(300, 350));
		setLocationRelativeTo(parent);
	}
	private void initData(){
		try{
		  List<String> result = StringUtils.convert(AdbManager.queryResult(new Command(AdbManager.ADB_PATH, " devices"), true), "");
		  for(String value : result){
			  if(StringUtils.isEmpty(value)) continue;
			  System.err.println(value);
			  listModel.addElement(value.replace("\t", " "));
		  }
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	private void initEvent(){
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent e) {
				dispose();
			}			
		});
	}
	private void initUI(){
	   JPanel mainPanel = getIContentPane();
	   mainPanel.setLayout(new BorderLayout());
	   mainPanel.add(new JLabel("Device list"), BorderLayout.NORTH);
	   
	   deviceList = new JList(listModel = new DefaultListModel());
	   deviceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	   mainPanel.add(new JScrollPane(deviceList), BorderLayout.CENTER);
	   
	   JPanel buttomPane = new JPanel(new FlowLayout(FlowLayout.CENTER));
	   mainPanel.add(buttomPane, BorderLayout.SOUTH);
	   
	   submitButton = new JButton("Submit");
	   cancelButton = new JButton("Cancle");
	   submitButton.addActionListener(new AbstractAction() {	
		private static final long serialVersionUID = 1L;
		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			
		}
	   });
	   cancelButton.addActionListener(new AbstractAction() {	
			private static final long serialVersionUID = 1L;
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		   });
	   buttomPane.add(submitButton);
	   buttomPane.add(cancelButton);
	}

}
